<?php
if(!defined('BLOG'))exit('不作死就不会死');
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/1/10
 * Time: 17:02
 */
/**
 * 加载语言
 * @param $key
 * @return mixed
 */
function L($key){
    $lang = base::load_config('system','lang');
    $path = ROOTPATH.'core'.DIRECTORY_SEPARATOR.'languages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.R_M.'_lang.php';
    include $path;
    return isset($LANG[$key])?$LANG[$key]:$key;
}
function my_addslashes($str){
    if(is_string($str))return $str;
    foreach($str as $key => $val){$str[$key] = my_addslashes(trim($val));}
    return $str;
}
function strmcrypt($str,$key=''){
    $key = $key == ''?base::load_config('system','auth_key'):$key;
    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_DES,MCRYPT_MODE_ECB),MCRYPT_RAND);//初始化向量
    $str_encrypt = mcrypt_encrypt(MCRYPT_DES,$key,$str,MCRYPT_MODE_ECB,$iv); //加密函数
    return $str_encrypt;
}
function strmcrypt_ex($str_encrypt,$key=''){
    $key = $key == ''?base::load_config('system','auth_key'):$key;
    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_DES,MCRYPT_MODE_ECB),MCRYPT_RAND);//初始化向量
    $str_decrypt = mcrypt_decrypt(MCRYPT_DES,$key,$str_encrypt,MCRYPT_MODE_ECB,$iv); //解密函数
    return $str_decrypt;
}

function createsecret(){
    $str = '<,/12?34>.5#67&98!^90%qwe+r_:"ty*uio~p|asdfghjk)lzx(cvb@nm';
    $secret = '';
    for($i=0;$i<8;$i++){
        $num = rand(0,strlen($str));
        $secret.=substr($str,$num,1);
    }
    return $secret;
}

